<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <link href="/css/font-awesome.css" rel="stylesheet">
    <link href="/css/datatables.min.css" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css" rel="stylesheet">
    <script src="/js/jquery-3.1.1.min.js"></script>
    <script src="/js/bootstrap.min.js"></script>
    <script src="/js/vue.js"></script>
</head>
<body style="background-color:whitesmoke">
<div id="admin">
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>用户管理</h2>
        <ol class="breadcrumb">
            <li>
                <a href="index.html">系统管理</a>
            </li>
            <li>
                <a>用户管理</a>
            </li>
            <li class="active">
                <strong>用户管理</strong>
            </li>
        </ol>
    </div>
</div>

<div class="wrapper wrapper-content animated fadeInRight">

    <div class="ibox-content m-b-sm border-bottom">
        <div class="row">
            <form role="form" class="form-horizontal">
                <div class="form-group">
                    <label class=" col-sm-2 control-label">员工编号</label>
                    <div class=" col-sm-2">
                        <input type="text" class="form-control" v-model="adminQuery.staffId" placeholder="请输入员工编号">
                    </div>

                    <label class=" col-sm-2 control-label">员工姓名</label>
                    <div class=" col-sm-2">
                        <input type="text" class="form-control" v-model="adminQuery.staffName" placeholder="请输入员工姓名">
                    </div>


                    <div>
                        <button class="btn btn-primary btn-sm" type="button"  @click="loadData()"><span class="glyphicon glyphicon-zoom-in" ></span> 查询</button>
                        <!--<button class="btn btn-primary btn-sm" type="button" @click="add()"><span class="glyphicon glyphicon-plus"></span> 新增</button>-->
                    </div>
                </div>
            </form>

        </div>

    </div>
    <div class="row">
        <div class="col-lg-12">

            <div class="ibox float-e-margins">

                <div class="ibox-content">

                    <table class="footable table table-stripped toggle-arrow-tiny" data-page-size="15">
                        <thead>
                        <tr>
                            <th data-hide="phone">员工编号</th>
                            <th data-hide="all">员工姓名</th>
                            <th data-hide="phone">员工性别</th>
                            <th data-toggle="true">员工出生日期</th>
                            <th data-hide="phone">员工电话号码</th>
                            <th data-hide="all">员工邮件地址</th>
                            <th data-hide="phone">员工学历</th>
                            <th data-toggle="true">员工部门</th>
                            <th data-hide="phone">员工职位</th>
                            <th data-hide="all">员工入职时间</th>
                            <th data-hide="phone">员工状态</th>
                            <th data-hide="phone">备注</th>
                            <th class="text-right" data-sort-ignore="true">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr v-for="x in list">
                            <td>{{x.staffId}}</td>
                            <td>{{x.staffName}}</td>
                            <td>{{x.staffSex}}</td>
                            <td>{{x.staffBirth}}</td>
                            <td>{{x.staffTel}}</td>
                            <td>{{x.staffEmail}}</td>
                            <td>{{x.staffEducation}}</td>
                            <td>{{x.staffDepartment}}</td>
                            <td>{{x.staffPost}}</td>
                            <td>{{x.staffEntryTime}}</td>
                            <td>{{x.staffState}}</td>
                            <td>{{x.remarks}}</td>
                            <td class="text-right">

                                <button class="btn-primary btn btn-sm" @click="update(x)"><span class="glyphicon glyphicon-tag"></span> 编辑</button>
                                <button class="btn-primary btn btn-sm"  @click="del(x)"><span class="glyphicon glyphicon-trash"></span> 删除</button>
                            </td>
                        </tr>
                        </tbody>
                    </table>

                    <div>
                        一共{{total}}条数据,一共{{totalPage}}页,当前第{{curPage}}页
                        <button class="btn btn-success btn-sm" type="button" @click="prePages()">上一页</button>
                        <button class="btn btn-success btn-sm" type="button" @click="nextPages()">下一页</button>
                        <button class="btn btn-success btn-sm" type="button" @click="indexPage()">首页</button>
                        <button class="btn btn-success btn-sm" type="button" @click="endPage()">尾页</button>
                        跳转到<input type="number" id="num" style="width: 40px" min="1" max="10" v-model="selectPage" @keyup="valNum">页
                        <button class="btn btn-success btn-sm" type="button" @click="changePage()">跳转</button>
                        <select v-model="adminQuery.row" @change="selectRow" >
                            <option value="3">每页3条</option>
                            <option value="5">每页5条</option>
                            <option value="10">每页10条</option>
                        </select>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

    <!-- 模态框编辑 -->
    <div id="edit" class="modal fade" style="top:200px">
        <div class="modal-dialog">

            <div class="modal-content">
                <!--头部-->
                <div class="modal-header">
                    <h4 align="center">{{title}}</h4>

                </div>
                <!--主题内容-->
                <div class="modal-body">
                    <form role="form" class="form-horizontal">

                        <div class="form-group">
                            <label class=" col-sm-2 control-label">员工编号</label>
                            <div class=" col-sm-10">
                                <input type="text" class="form-control" disabled="disabled" v-model="admin.staffId"  placeholder="请输入员工编号">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class=" col-sm-2 control-label">员工姓名</label>
                            <div class=" col-sm-10">
                                <input type="text" class="form-control"  v-model="admin.staffName"  placeholder="请输入员工姓名">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class=" col-sm-2 control-label">员工性别</label>
                            <div class=" col-sm-10">
                                <select class="form-control" v-model="admin.staffSex">
                                    <option  selected value="男">男</option>
                                    <option  selected value="女">女</option>
                                </select>

                            </div>
                        </div>

                        <div class="form-group">
                            <label class=" col-sm-2 control-label">员工出生日期</label>
                            <div class=" col-sm-10">
                                <input type="text" class="form-control"  v-model="admin.staffBirth"  placeholder="请输入员工日期">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class=" col-sm-2 control-label">员工电话号码</label>
                            <div class=" col-sm-10">
                                <input type="text" class="form-control" v-model="admin.staffTel"  placeholder="请输入员工电话号码">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class=" col-sm-2 control-label">员工邮箱</label>
                            <div class=" col-sm-10">
                                <input type="text" class="form-control" v-model="admin.staffEmail"  placeholder="请输入员工邮箱">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class=" col-sm-2 control-label">员工学历</label>
                            <div class=" col-sm-10">
                                <select class="form-control" v-model="admin.staffEducation">
                                    <option  selected value="专科">专科</option>
                                    <option  selected value="本科">本科</option>
                                    <option  selected value="硕士研究生">硕士研究生</option>
                                    <option  selected value="博士研究生">博士研究生</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class=" col-sm-2 control-label">员工部门</label>
                            <div class=" col-sm-10">
                                <input type="text" class="form-control"  disabled="disabled" v-model="admin.staffDepartment" >
                            </div>
                        </div>

                        <div class="form-group">
                            <label class=" col-sm-2 control-label">员工职务</label>
                            <div class=" col-sm-10">
                                <input type="text" class="form-control" disabled="disabled" v-model="admin.staffPost"  >
                            </div>
                        </div>

                        <div class="form-group">
                            <label class=" col-sm-2 control-label">员工状态</label>
                            <div class=" col-sm-10">

                                <select class="form-control" v-model="admin.staffState">
                                    <option  selected value="在职">在职</option>
                                    <option  selected value="不在职">兼职</option>
                                    <option  selected value="离职">离职</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class=" col-sm-2 control-label">备注</label>
                            <div class=" col-sm-10">
                                <input type="text" class="form-control" v-model="admin.remarks"  placeholder="请输入备注">
                            </div>
                        </div>

                    </form>
                </div>

                <!--底部-->
                <div class="modal-footer">
                    <button class="btn btn-primary btn-sm" type="button" @click="closeEditWin()"><span class="glyphicon glyphicon-remove"></span>关闭</button>

                    <button class="btn btn-primary btn-sm"  @click="saveEditAdmin"><span class="glyphicon glyphicon-save"   ></span>保存</button>
                </div>

            </div>
        </div>
    </div>
    <!--模态框编辑-->
</div>
</body>

<script>

    new Vue({
        el:"#admin",
        data:{
            list:[],
            total:0,//总条数
            totalPage:0,//总页数
            selectPage:1,//选择页数
            adminQuery:{ //查询对象
                page:1,
                row:3,
                staffId:null,
                staffName:"",
            },
            prePage:0,//上一页
            nextPage:0,//下一页.
            curPage:0,//当前页
            admin:{
                id:0,
                staffId:0,
                staffName:"",
                staffSex:"",
                staffBirth:"",
                staffTel:"",
                staffEmail:"",
                staffEducation:"",
                staffDepartment:"",
                staffPost:"",
                staffEntryTime:"",
                staffState:"",
                remarks:"",
            },
            title:"用户修改"

        },
        methods:{
            loadData:function () {
                var self = this;
                $.ajax({
                    url:"/empInformation/empList",//请求地址
                    type:"get",
                    data:self.adminQuery,
                    dataType:"json",//返回的数据类型
                    success:function (data) {
                        console.log(data);
                        self.list = data.list;
                        self.total = data.total;
                        self.totalPage = data.totalPage;
                        self.prePage = data.prePage;
                        self.nextPage = data.nextPage;
                        self.curPage = data.curPage;

                    }

                })
            },
            prePages:function () {//上一页
                this.adminQuery.page = this.prePage;
                //刷新
                this.loadData();

            },
            nextPages:function () {
                this.adminQuery.page = this.nextPage;
                //刷新
                this.loadData();

            },
            indexPage:function () {//首页
                this.adminQuery.page = 1
                //刷新
                this.loadData();

            },
            endPage:function () {//尾页
                this.adminQuery.page = this.totalPage;
                //刷新
                this.loadData();

            },
            changePage:function () {//跳转
                if(this.selectPage>this.totalPage){
                    this.adminQuery.page = this.totalPage;
                }else{
                    this.adminQuery.page = this.selectPage;
                }
                //刷新
                this.loadData();

            },
            selectRow:function () {//选择条数
                this.adminQuery.page=1
                //刷新
                this.loadData();

            },
            valNum:function () {
                //定义正则表达式对象
                var dd =/^[\u4e00-\u9fa5]{0,}$/
                //如果输入的汉字，就显示1
               if(dd.test(this.selectPage)) {
                   this.selectPage=1
               }else{
                   console.log("=="+this.selectPage)
                   //如果输入的值大于总页数，就回到最大值
                   if(this.selectPage>this.totalPage){
                       this.selectPage = this.totalPage;
                   }
               }


            },
            update:function(x) {//打开修改模态框
                $("#edit").modal("show")
                //数据回显
                this.admin = x;
                this.title="用户修改";

            },
            /*add :function () {//打开新增模态框
                $("#one").modal("show")
                this.title="用户新增";
                //清空
                this.admin.id=null;
                this.admin.staffId=null;
                this.admin.staffName="";
                this.admin.staffSex="";
                this.admin.staffBirth="";
                this.admin.staffTel="";
                this.admin.staffEmail="";
                this.admin.staffEducation="";
                this.admin.staffDepartment="";
                this.admin.staffPost="";
                this.admin.staffEntryTime="";
                this.admin.staffState="";
                this.admin.remarks="";

            },*/
            saveEditAdmin:function () {//修改保存
                var url="/empInformation/update";
                var self = this;
                console.log(url);
                $.ajax({
                    url:url,
                    type:"post",
                    contentType:"application/x-www-form-urlencoded",
                    data:self.admin,
                    dataType:"json",
                    success:function (data) {
                        console.log(data);
                        alert(data.info);
                        if(data.info=="修改成功"){
                            //关闭模态框
                            $("#edit").modal("hide")
                            //刷新
                            self.loadData();
                        }else {
                           alert("修改失败！！")
                            self.loadData();
                        }
                    }


                })

            },

            /*saveAddAdmin:function () {//新增保存
                var url="/empInformation/add";
                var self = this;
                console.log(url);
                $.ajax({
                    url:url,
                    type:"post",
                    contentType:"application/x-www-form-urlencoded",
                    data:self.admin,
                    dataType:"json",
                    success:function (data) {
                        console.log(data);
                        alert(data.info);
                        if(data.info=="新增成功"){
                            //关闭模态框
                            $("#one").modal("hide")
                            //刷新
                            self.loadData();
                        }else {
                            alert("新增失败！！")
                            self.loadData();
                        }
                    }


                })

            },*/
            /*closeAddWin:function () {//关闭模态框
                $("#one").modal("hide")
            },*/
            closeEditWin:function () {//关闭模态框
                $("#edit").modal("hide");
                this.loadData()
            },
            del:function (x) {
                flag =confirm("你确定要删除吗？");
                var self= this;

                if (flag){
                    $.ajax({
                        url:"/empInformation/del",
                        type:"post",
                        contentType:"application/x-www-form-urlencoded",
                        data:{"id":x.staffId},
                        dataType:"json",
                        success:function (data) {
                            alert(data.info);
                            if(data.info=="删除成功"){
                                self.loadData();
                            }
                        }


                    })
                }


            }


        },
        mounted(){
            //运行loadData函数
            this.loadData();
        }
    })



</script>
</html>
